package com.qf.service.impl;

import com.qf.mapper.StuMapper;
import com.qf.pojo.Stu;
import com.qf.service.StuService;
import com.qf.utis.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
* @author LC
* @description 针对表【stu】的数据库操作Service实现
* @createDate 2025-10-01 18:10:46
*/
@Service
public class StuServiceImpl implements StuService {
    @Autowired
    private StuMapper stuMapper;

    @Override
    public R getById(Integer id) {
        if (id == null){
            return R.error("id不能为空");
        }
        return R.ok(stuMapper.getById(id));
    }

    @Override
    public R getAll() {
        return R.ok(stuMapper.getAll());
    }

    @Override
    public R getAllByCondition(HashMap<String, Object> map) {
        return R.ok(stuMapper.getAllByCondition(map));
    }

    @Override
    public R add(Stu stu) {
        return stuMapper.add(stu) > 0 ? R.ok() : R.error( "添加失败");
    }

    @Override
    public R update(Stu stu) {
        return stuMapper.update(stu) > 0 ? R.ok() : R.error( "修改失败");
    }

    @Override
    public R delete(Integer id) {
        return stuMapper.delete(id) > 0 ? R.ok() : R.error( "删除失败");
    }

    @Override
    public R deleteBatch(List<Integer> ids) {
        return stuMapper.deleteBatch(ids) > 0 ? R.ok() : R.error( "批量删除失败");
    }

    @Override
    public R getAllStuAndClass() {
        return R.ok(stuMapper.getAllStuAndClass());
    }

    @Override
    public R getStuAndALLSubject(Integer id) {
        return R.ok(stuMapper.getStuAndALLSubject(id));
    }

    @Override
    public R getStuAndALLSubjectAndTeacher(Integer id) {
        return R.ok(stuMapper.getStuAndALLSubjectAndTeacher(id));
    }
}
